﻿namespace NetFx.MSIL
{
  using System;
  using System.Text;
  using System.Collections;

  using System.Reflection;
  using System.Reflection.Emit;
  using System.Runtime.InteropServices;

  using System.Diagnostics;
  using System.Diagnostics.CodeAnalysis;
  using System.Diagnostics.SymbolStore;

  public class FieldGenerator:MemberGenerator
  {
    #region Statics
    public static FieldGenerator of(FieldBuilder builder)
    {
      return new FieldGenerator(builder);
    }
    #endregion
    #region Fields
    protected int offset = 0;
    protected object defaultValue = null;
    #endregion
    #region Properties
    public override DefType GeneratorType
    {
      get
      {
        return DefType.Field;
      }
    }
    public virtual FieldBuilder Builder
    {
      get
      {
        return this.builder as FieldBuilder;
      }
    }
    public virtual FieldAttributes Attributes
    {
      get
      {
        return this.Builder.Attributes;
      }
    }
    public virtual Type FieldType
    {
      get
      {
        return this.Builder.FieldType;
      }
    }
    public virtual FieldToken FieldToken
    {
      get
      {
        return this.Builder.GetToken();
      }
    }
    public virtual object DefaultValue
    {
      get
      {
        return this.defaultValue;
      }
      set
      {
        this.Builder.SetConstant(this.defaultValue = value);
      }
    }
    public virtual int FieldOffset
    {
      get
      {
        return this.offset;
      }
      set
      {
        this.Builder.SetOffset(this.offset = value);
      }
    }
    #endregion
    #region Constructors
    public FieldGenerator(FieldBuilder builder):base(builder)
    {

    }
    #endregion
    #region Methods

    #endregion
    #region Utils
    protected override void Dispose(bool disposing)
    {
      if (disposing)
      {
        this.defaultValue = null;
      }
      base.Dispose(disposing);
    }
    #endregion
  }
}
